﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace DataLibrary
{
    public class Ctbl_Product_Lang:IData<tbl_Product_Lang>
    {
        public Ctbl_Product_Lang(String myconnecString) : base(myconnecString) { }


        

        public override List<tbl_Product_Lang> GetAll(tbl_Product_Lang item)
        {
            throw new NotImplementedException();
        }


        public override tbl_Product_Lang GetItemById(object id)
        {
            return GetAll().SingleOrDefault(p => p.IdProductLang == Convert.ToInt32(id));
        }

        public override tbl_Product_Lang GetItem(IDataReader dr)
        {
            tbl_Product_Lang obj = new tbl_Product_Lang();
            obj.Description = Convert.ToString(dr[tbl_Product_Lang.c_Description]);
            obj.IdLang = Convert.ToInt32(dr[tbl_Product_Lang.c_idLang]);
            obj.IdProduct = Convert.ToInt32(dr[tbl_Product_Lang.c_idProduct]);
            obj.IdProductLang= Convert.ToInt32(dr[tbl_Product_Lang.c_idProductLang]);
            obj.IntroProduct = Convert.ToString(dr[tbl_Product_Lang.c_introProduct]);
            obj.NameProduct = Convert.ToString(dr[tbl_Product_Lang.c_nameProduct]);
            obj.Price = Convert.ToDecimal(dr[tbl_Product_Lang.c_Price]);

            return obj;
        }

        public override List<tbl_Product_Lang> GetAll()
        {
            return GetAll("select * from " + tbl_Product_Lang.b_tbl_Product_Lang, CommandType.Text);
        }

        protected override int InsertOnSubmit(tbl_Product_Lang item, int t)
        {
            int id = -1;
            String strProName = "proProductLang";
            id = connec.ExecuteNonQuery(strProName, CommandType.StoredProcedure,new SqlParameter("@flag",t),
                new SqlParameter("@"+tbl_Product_Lang.c_Description,item.Description),new SqlParameter("@"+tbl_Product_Lang.c_idLang,item.IdLang),
                new SqlParameter("@"+tbl_Product_Lang.c_idProduct,item.IdProduct),new SqlParameter("@"+tbl_Product_Lang.c_idProductLang,item.IdProductLang),
                new SqlParameter("@"+tbl_Product_Lang.c_introProduct,item.IntroProduct),new SqlParameter("@"+tbl_Product_Lang.c_nameProduct,item.NameProduct),
                new SqlParameter("@"+tbl_Product_Lang.c_Price,item.Price));
            return id;
        }
    }
}
